package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.UpdateEnableRequest;
import com.mes.cloud.api.dto.request.position.PositionUpdateDataAuthRequest;
import com.mes.cloud.api.dto.request.position.SysPositionPageRequest;
import com.mes.cloud.api.dto.request.position.SysPositionRequest;
import com.mes.cloud.api.dto.response.organization.SysOrganizationPositionDto;
import com.mes.cloud.api.dto.response.position.SysPositionDetailsDto;
import com.mes.cloud.api.dto.response.position.SysPositionDto;
import com.mes.cloud.api.dto.response.position.SysPositionPageDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xy
 * @version 2019-08-03 08:39:11
 * @email yuan.xue3@pactera.com
 */
@Api(tags = "岗位", value = "岗位接口")
@RestController
@RequestMapping(value = "/sysPosition")
public class SysPositionController {

    private SysPositionService sysPositionService;

    @Autowired
    public SysPositionController(SysPositionService sysPositionService) {
        this.sysPositionService = sysPositionService;
    }

    /**
     * 功能: 岗位分页查询
     *
     * @param pageRequest
     * @return JsonResult<CommPager<SysPositionDto>>
     */
    @ApiOperation(value = "岗位分页查询", notes = "岗位分页查询")
    @PostMapping(value = "/pageList")
    public JsonResult<CommPager<SysPositionPageDto>> pageList(@RequestBody SysPositionPageRequest pageRequest) {
        return sysPositionService.pageList(pageRequest);
    }

    /**
     * 功能: 岗位查询所有
     *
     * @param sysPositionRequest
     * @return JsonResult<List<SysPositionDto>>
     */
    @ApiOperation(value = "岗位查询所有", notes = "岗位查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<SysPositionDto>> list(@RequestBody SysPositionRequest sysPositionRequest) {
        return sysPositionService.list(sysPositionRequest);
    }

    /**
     * 功能: 岗位新增
     *
     * @param sysPositionRequest
     * @return JsonResult
     */
    @ApiOperation(value = "岗位新增", notes = "岗位新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody SysPositionRequest sysPositionRequest) {
        return sysPositionService.insert(sysPositionRequest);
    }

    /**
     * 功能: 岗位修改
     *
     * @param sysPositionRequest
     * @return JsonResult
     */
    @ApiOperation(value = "岗位修改", notes = "岗位修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody SysPositionRequest sysPositionRequest) {
        return sysPositionService.update(sysPositionRequest);

    }

    /**
     * <岗位查看详情>
     *
     * @param id
     * @return com.shinho.tntframe.core.common.model.JsonResult<com.shinho.crm.base.api.dto.response.position.SysPositionDetailsDto>
     * @author xy
     * @date 2019/8/8 17:21
     */
    @ApiOperation(value = "岗位查看详情", notes = "岗位查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "岗位主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<SysPositionDetailsDto> get(@PathVariable String id) {
        return sysPositionService.get(id);
    }

    /**
     * <岗位禁用启用>
     *
     * @param updateEnableRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author xy
     * @date 2019/8/8 17:20
     */
    @ApiOperation(value = "岗位禁用启用", notes = "岗位禁用启用")
    @PostMapping(value = "/updateEnableFlag")
    public JsonResult updateEnableFlag(@Valid @RequestBody UpdateEnableRequest updateEnableRequest) {
        return sysPositionService.updateEnableFlag(updateEnableRequest);
    }

    /**
     * <组织岗位分页查询>
     *
     * @param pageRequest
     * @return com.shinho.tntframe.core.common.model.JsonResult<com.shinho.tntframe.core.common.model.CommPager<com.shinho.crm.base.api.dto.response.organization.SysOrganizationPositionDto>>
     * @author xy
     * @date 2019/8/8 14:49
     */
    @ApiOperation(value = "组织岗位分页查询", notes = "组织岗位分页查询")
    @PostMapping(value = "/pageOrganizationPositionList")
    public JsonResult<CommPager<SysOrganizationPositionDto>> pageOrganizationPositionList(@Valid @RequestBody SysPositionPageRequest pageRequest) {
        return sysPositionService.pageOrganizationPositionList(pageRequest);
    }

    /**
     * 岗位数据授权
     * @param positionUpdateDataAuthRequest
     * @return
     */
    @ApiOperation(value = "岗位数据授权", notes = "岗位数据授权")
    @PostMapping(value = "/updatePositionDataAuth")
    public JsonResult updatePositionDataAuth(@Valid @RequestBody PositionUpdateDataAuthRequest positionUpdateDataAuthRequest) {
        return sysPositionService.updatePositionDataAuth(positionUpdateDataAuthRequest);
    }
}
